<template>
  <div class="vertical-bar">
    <el-text class="vertical-font">2024 年度专题数据统计中心</el-text>
    <div ref="target" style="width:90%; height:500px;"></div>
  </div>
</template>

<script setup lang="ts">
import {onMounted, ref, watch, nextTick} from "vue";
import * as echarts from "echarts";
import {IndexTopicArticleVo} from "@/store/types";

const props = defineProps<{
  data: IndexTopicArticleVo[];
}>();

let chart: any = null;
const target = ref(null);

onMounted(() => {
  chart = echarts.init(target.value);
  nextTick();
});
nextTick(() => {
  renderChart()
})
const renderChart = () => {
  const options = {
    // 雷达图的坐标系配置
    radar: {
      // 绘制类型 polygon circle
      shape: "polygon",
      // 中心坐标
      center: ["50%", "50%"],
      // 半径
      radius: "80%", // 取短边的80%
      // 起始角度
      startAngle: 120,
      // 轴线配置
      axisLine: {
        lineStyle: {
          color: "rgba(0,0,0, .8)",
        },
      },
      // 分割线配置
      splitLine: {
        show: true,
        lineStyle: {
          width: 1,
          color: "rgba(0,0,0, .8)",
        },
      },
      // 指示器
      indicator: props.data.map((item) => ({
        name: item.title,
      })),
      // 指示器名称配置
      axisName: {
        fontSize: 14,
      },
      // 坐标轴在 grid 区域中的分隔区域配置
      splitArea: {
        show: false,
      },
    },
    // 坐标极点
    polar: {
      center: ["50%", "50%"],
      radius: "0%",
    },
    // 极坐标系的角度轴配置
    angleAxis: {
      min: 0,
      // 强制设置坐标轴分割间隔
      interval: 5,
      // 是否顺时针 true顺时针 false逆时针
      clockwise: false,
    },
    // 径向轴
    radiusAxis: {
      min: 0,
      interval: 20,
      splitLine: {
        show: true,
      },
    },
    // 核心配置
    series: {
      type: "radar",
      symbol: "circle",
      symbolSize: 10,
      itemStyle: {
        color: "#05D5FF",
      },
      areaStyle: {
        color: "#05D5FF",
        opacity: 0.6,
      },
      lineStyle: {
        width: 2,
        color: "#303030",
      },
      label: {
        show: true,
        color: "#303030",
      },
      data: [
        {
          value: props.data.map(item => item.totals),
        },
      ],
    },
  };
  chart.setOption(options);
};

watch(() => props.data, renderChart);

window.addEventListener("resize", () => {
  chart.resize();
});
</script>


<style lang="scss" scoped>
.vertical-bar {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: start;
  justify-content: center;
  background-color: #FFFFFF;
  border-radius: 20px;
  box-shadow: rgba(100, 100, 111, 0.2) 0px 7px 29px 0px;

  .vertical-font {
    margin-left: 20px;
    font-size: 18px;
    font-weight: bold;
  }
}
</style>
